<style>
  .picImg {
    width: 40px;
    height: 40px;
  }
</style>
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="listQuery.startTime"
        align="right"
        type="datetime"
        placeholder="开始日期"
        :picker-options="pickerOptions"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      -
      <el-date-picker
        v-model="listQuery.endTime"
        align="right"
        type="datetime"
        placeholder="结束日期"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      <el-button type="primary" @click="getlistQuery">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row
              @row-click="detail">
      <el-table-column fixed align="center" min-width="100" label="表单ID" prop="id"/>
      <el-table-column align="center" min-width="100" label="表单编号" prop="formNo"/>
      <el-table-column align="center" min-width="100" label="上传时间" prop="addTime"/>
      <el-table-column align="center" min-width="100" label="保险公司ID" prop="insuranceID"/>
      <el-table-column align="center" min-width="100" label="保代公司ID" prop="insuragentID"/>
      <el-table-column align="center" min-width="100" label="保理公司ID" prop="factoringID"/>
      <el-table-column align="center" min-width="100" label="保单总数" prop="billCount"/>
      <el-table-column align="center" min-width="100" label="费用总额" prop="amount"/>
      <el-table-column align="center" min-width="100" label="表单状态" prop="status"/>
      <el-table-column align="center" min-width="100" label="保代公司/权益服务商处理时间" prop="advanceTime"/>
      <el-table-column align="center" min-width="100" label="需要垫资保单数" prop="advanceCount"/>
      <el-table-column align="center" min-width="100" label="需要垫资金额" prop="advanceAmount"/>
      <el-table-column align="center" min-width="100" label="垫资支付时间" prop="advanceTime"/>
      <el-table-column align="center" min-width="100" label="回款总额" prop="repayAmount"/>
      <el-table-column align="center" min-width="100" label="回款时间" prop="repayTime"/>
      <el-table-column align="center" min-width="100" label="上传备注" prop="remarkUp"/>
      <el-table-column align="center" min-width="100" label="垫资申请备注" prop="remarkAdv"/>
      <el-table-column align="center" min-width="100" label="垫资利息" prop="interest"/>
      <el-table-column align="center" min-width="100" label="利息付款时间" prop="interestTime"/>
      <el-table-column fixed="right" align="center" label="操作" width="250" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="danger" size="mini" @click="rmb(scope.row)">
            垫资
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="editDialogVisible" title="表单明细">
      <el-table v-loading="listLoading1" :data="list1" element-loading-text="正在查询中。。。" border fit highlight-current-row>
        <el-table-column align="center" min-width="100" label="表单ID" prop="id"/>
        <el-table-column align="center" min-width="100" label="保单号或合同号" prop="billNo"/>
        <el-table-column align="center" min-width="100" label="保单金额" prop="billAmount"/>
        <el-table-column align="center" min-width="100" label="代理手续费/服务费" prop="fee"/>
        <el-table-column align="center" min-width="100" label="是否需要垫资" prop="isAdvance"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editDialogVisible = false">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {doGet, doPost} from '@/api'
  import Pagination from '@/components/Pagination'

  const FETCH_PAGE = 'blagentfee.html'
  const FETCH_URL = {
    LIST: `${FETCH_PAGE}?op=list`,
    CREATE: `${FETCH_PAGE}?op=billlist`,
    EDIT: `${FETCH_PAGE}?op=check`,
    DELETE: `${FETCH_PAGE}?op=pay`,
    IMPORT: `${FETCH_PAGE}?op=import`
  }
  export default {
    name:'blagentfee',
    components: {Pagination},
    data() {
      return {
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        list: [],
        list1:[],
        listLoading: true,
        listLoading1:true,
        listQuery: {
          startTime: undefined,
          endTime: undefined,
          status: undefined
        },
        editDialogVisible: false,
        editForm: {
          id: undefined,
          billNo: undefined,
          billAmount: undefined,
          fee: undefined,
          isAdvance: undefined
        },
      }
    },
    created() {
      this.getList()
    },
    methods: {
      getList() {
        this.listLoading = true
        doGet(FETCH_URL.LIST, this.listQuery).then(response => {
//          console.log(response)
          this.list = response.rows
          this.total = response.rows.length
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
      },
      detail(row) {
        this.editDialogVisible=true
        this.listLoading1=true
//        console.log(this.list)
        doGet(FETCH_URL.CREATE, {id:row.id}).then(response => {
//          console.log(response)
          this.list1=response.rows
          this.listLoading1=true
//          this.editForm.id = response.rows.id
//          this.editForm.billNo = response.rows.billNo
//          this.editForm.billAmount = response.rows.billAmount
//          this.editForm.fee = response.rows.fee
//          this.editForm.isAdvance = response.rows.isAdvance
        }).catch(() => {
//          this.total = 0
          this.listLoading1=false
        })
      },
      getlistQuery(){
        this.getList()
      },
      rmb(row) {
//        console.log(row)
//        doGet(FETCH_URL.EDIT, {id:row.id}).then(response => {
////          console.log(response)
//          this.$confirm('垫资打款确认', '提示', {
//            confirmButtonText: '确定',
//            cancelButtonText: '取消',
//            type: 'warning'
//          }).then(() => {
//            this.$message({
//              type: 'success',
//              message: '垫资成功!'
//            });
//          }).catch(() => {
//            this.$message({
//              type: 'info',
//              message: '已取消垫资'
//            });
//            this.$notify.error({
//              title: '成功',
//              message: response.message
//            })
//          }).catch(() => {
//            this.$notify.error({
//              title: '失败',
//              message: response.message
//            })
//          })
//        })
      }
    }
  }
</script>
